package com.hxy.controller;

import com.github.pagehelper.PageInfo;
import com.hxy.common.JsonResult;
import com.hxy.pojo.Rpkind;
import com.hxy.pojo.Trainnote;
import com.hxy.pojo.vo.TrainnoteVo;
import com.hxy.service.RpkindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hxy
 */
@RestController
@RequestMapping("/admin/rpkind")
public class RpkindController {

    @Autowired
    private RpkindService rpkindService;

    @RequestMapping("/list")
    public JsonResult selectAll(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                @RequestParam(value = "limit", required = false, defaultValue = "10") int limit) {
        page = page == null ? 1 : page;
        PageInfo<Rpkind> trainnotePageInfo = rpkindService.selectRpkind(page, limit);
        return new JsonResult(0, "成功", trainnotePageInfo);
    }
    @RequestMapping("/findById")
    public JsonResult findById(Integer id) {

        Rpkind byId = rpkindService.findById(id);
        return new JsonResult(0, "成功", byId);
    }
   //待定
    @RequestMapping("/addRpkind")
    public JsonResult addRpkind(Rpkind rpkind) {

        int i = rpkindService.insertRpkind(rpkind);
        if (i>0){

            return new JsonResult(0,"添加成功",null);
        }else{
            return new JsonResult(1,"添加失败",null);
        }

    }

    /**
     *
     * @param pageNo
     * @param limit
     * @param name
     * @return
     */
    @RequestMapping("/findRpkindByTJ")
    public JsonResult findRpkindByTJ(@RequestParam(value = "page", required = false, defaultValue = "1") Integer pageNo,
                                     @RequestParam(value = "limit", required = false, defaultValue = "10") int limit,
                                     @RequestParam(value = "name", required = false, defaultValue = "") String name) {
        PageInfo<Rpkind> rpkindPageInfo = rpkindService.findRpkindByTJ(name, pageNo, limit);
        return new JsonResult(0, "成功", rpkindPageInfo);
    }
    @RequestMapping("/updataRpkind")
    public  JsonResult updataRpkind(Rpkind rpkind){

        int i = rpkindService.updateRpkind(rpkind);
        if (i>0){

            return new JsonResult(0,"修改成功",null);
        }else{
            return new JsonResult(1,"修改失败",null);
        }

    }
    @RequestMapping("/deleteRpkind")
    public  JsonResult deleteRpkind(Integer id){

        int i = rpkindService.deleteRpkind(id);
        if (i>0){

            return new JsonResult(0,"删除成功",null);
        }else{
            return new JsonResult(1,"删除失败",null);
        }

    }
}
